//
//  NSOperationQueueAdditions.m
//  Tint
//
//  Created by Kevin Wu on 2/22/12.
//  Copyright (c) 2012 Telligenty. All rights reserved.
//

#import "NSOperationQueueAdditions.h"

@implementation NSOperationQueue (Tint)


#pragma mark - Singleton

+ (NSOperationQueue *)sharedObject {
    static NSOperationQueue *sharedOperationQueue = nil;
	if (sharedOperationQueue == nil) {
        sharedOperationQueue = [[self alloc] init];
        [sharedOperationQueue setMaxConcurrentOperationCount:4];
    }
    return sharedOperationQueue;
}



#pragma mark - Safely add

- (void)addOperationSafely:(NSOperation *)operation {
    if ([operation isCancelled] || 
        [operation isExecuting] || 
        [operation isFinished] || 
        [[self operations] containsObject:operation]) {
        return;
    }
    
    [self addOperation:operation];
}

@end
